package com.wcansoft.baseWeb.mybatis_plugin.dao;

/*
 * 条件和赋值类
 * 鲍庆丰
 * 2007-3-29
 * baoqingfeng@gmail.com
 */
public class ConditionValue {
	private String condition;
	private Object[] vals;
	
	
	/**
	 * 条件和值对象构造函数
	 * @param conditon 条件
	 * @param values 任意多个值,注意值个数要和条件中的?号个数相同
	 */
	public ConditionValue(String conditon,Object ... values)
	{
		this.condition = conditon;
		if(values!=null && values.length>0)
			this.vals = values;
	}
	
	
	public int size()
	{
		if(vals==null || vals.length==0)
			return 0;
		return vals.length;
	}
	
	boolean isInExclue(int pos , int[] excludePos)
	{
		if(excludePos==null || excludePos.length==0)
			return false;
		
		for(int iPos : excludePos)
		{
			if(iPos==pos)
				return true;
		}
		return false;
	}
	
	
	
	public String getCondition() {
		return condition;
	}
	public void setCondition(String condition) {
		this.condition = condition;
	}
	public Object[] getVals() {
		return vals;
	}
	public void setVals(Object[] vals) {
		this.vals = vals;
	}
	
	public String toString()
	{
		if(condition==null || condition.length()==0 || vals==null || vals.length==0)
			return condition;
		return String.format(condition.replaceAll("?", "%s"), vals);
	}
}
